<?php
/**
 * 从决策系统中间表取样衣数据
 * @author sundongdong
 * @date 2016-09-27
 */
class Cron_Model_Decision_Sample extends Model_Base {
	private $db = '';
	private $host_db = '';
	
	public function __construct(){
		$this->db = $this->db('dms_db');
		$this->host_db = $this->db('write_db');
	}
	/**
	 * 获取总数
	 */
	public function getAccout() {
		return $this->db->fetchOne("SELECT count(*) from public_dm_cp_pro_monitor");
	}
	/**
	 * 分批获取数据
	 * @param number $start
	 * @param number $limit
	 */
	public function getData($start = 0,$limit = 1000) {
		$sql = "SELECT * FROM public_dm_cp_pro_monitor LIMIT ".$start.",".$limit;
		return $this->db->fetchAll($sql);
	}
	/**
	 * 查看样衣推广是否存在
	 */
	public function existFb($sku) {
		return $this->host_db->fetchOne("select id from sample_cloth_fb where sku = :sku", ['sku'=>$sku]);
	}
	/**
	 * 更新样衣数据
	 */
	public function updateFb($data, $id) {
		$this->host_db->beginTransaction();
		try {
			$this->host_db->update('sample_cloth_fb', $data, "id=".$id);
			$this->host_db->commit();
		} catch (Exception $e) {
			throw $e;
		}
	}
}